
var o = "https://duilu.showtimetech.com/duilu/";
module.exports = {
    request: function(o, e, t, a) {
        this.requestLoading(o, e, null, t, a);
    },
    reget: function(o, e, t, a) {
        this.regetLoading(o, e, null, t, a);
    },

    //post请求
    requestLoading: function(e, t, a, r, s) {
        console.log(a)
        wx.showNavigationBarLoading(), "" == a ? wx.showLoading({
            title: "加载中"
        }) : null == a || wx.showLoading({
            title: a
        });
        var n = "";
        try {
            n = wx.getStorageSync("token");
        } catch (o) {}
        console.log("url:", o + e),  t.token=n, wx.request({
            url: o + e,
            data: t,
            header: {
                "content-type": "application/x-www-form-urlencoded",
                //  "token":n 
            },
            method: "post",
            success: function(o) {
                console.log(o)
                console.log(o.statusCode), console.log(o.header), wx.hideNavigationBarLoading(), console.log(r)
                null != a && wx.hideLoading(), 1 == o.data.code ? (console.log(o.data.data), r(o.data))  : 0 == o.data.code ? (wx.showToast({
                    icon: "forbidden",
                    title: o.data.msg,
                })): 500 == o.data.code ? (wx.showToast({
                    image: "../../assets/images/jg_hud_error_3x.png",
                    title: null != o.data.errorMsg ? o.data.errorMsg : "服务器异常，请稍后！",
                    success: function() {
                        return console.log(null != o.data.errorMsg ? o.data.errorMsg : "服务器异常，请稍后！");
                    }
                }), o.data.msg = o.data.errorMsg, s(o.data)) : 401 == o.data.code ? wx.redirectTo({
                    url: "../login/login"
                }) : 400 == o.data.code && wx.showToast({
                    image: "../../assets/images/jg_hud_error_3x.png",
                    title: "请求参数有误！",
                    success: function() {
                        return console.log("请求参数有误！");
                    }
                });
            },
            fail: function(o) {
                wx.hideNavigationBarLoading(), null != a && wx.hideLoading(), wx.showToast({
                    icon: "forbidden",
                    title: "加载数据失败"
                }), s();
            },
            complete: function(o) {}
        });
    },
     //get请求
     regetLoading: function(e, t, a, r, s) {
         console.log(a)
        wx.showNavigationBarLoading(), "" == a ? wx.showLoading({
            title: "加载中"
        }) : null == a || wx.showLoading({
            title: a
        });
        var n = "";
        try {
            n = wx.getStorageSync("token");
        } catch (o) {}
        // console.log("url:", o + e), 
          wx.request({
            url: o + e,
            data: t,
            header: {
                'Content-Type': 'application/json',
                "token":n 
            },
            method: "get",
            success: function(o) {
                wx.hideNavigationBarLoading(), 
                null != a && wx.hideLoading(), 1 == o.data.code ? (console.log(o.data.data), r(o.data)) :0 == o.data.code ? (wx.showToast({
                    icon: "forbidden",
                    title: o.data.msg,
                })): 500 == o.data.code ? (wx.showToast({
                    image: "../../assets/images/jg_hud_error_3x.png",
                    title: null != o.data.errorMsg ? o.data.errorMsg : "服务器异常，请稍后！",
                    success: function() {
                        return console.log(null != o.data.errorMsg ? o.data.errorMsg : "服务器异常，请稍后！");
                    }
                }), o.data.msg = o.data.errorMsg, s(o.data)) : -1 == o.data.code ? wx.redirectTo({
                    url: "../login/login"
                }) : 400 == o.data.code && wx.showToast({
                    image: "../../assets/images/jg_hud_error_3x.png",
                    title: "请求参数有误！",
                    success: function() {
                        return console.log("请求参数有误！");
                    }
                });
            },
            fail: function(o) {
                wx.hideNavigationBarLoading(), null != a && wx.hideLoading(), wx.showToast({
                    icon: "forbidden",
                    title: "加载数据失败"
                }), s();
            },
            complete: function(o) {}
        });
    },
    
};